package com.mergeades.chp01;

public class ConcurrencyTest {
    private static final long count = 100001;

    public static void main(String[] args) throws InterruptedException {
        concurrency();
        serial();
    }
    private static void concurrency() throws InterruptedException {
        long start = System.nanoTime();
        Thread thread = new Thread(() -> {
            int a = 0;
            for (int i = 0; i < count; i++) {
                a += 5;
            }
        });
        thread.start();
        int b = 0;
        for (int i = 0; i < count; i++) {
            b--;
        }
        long tooks = System.nanoTime() - start;
        thread.join();
        System.out.println("concurrency :" + tooks + " ms; b= " + b);
    }

    private static void serial() {
        long start = System.nanoTime();
        int a = 0;
        for (int i = 0; i < count; i++) {
            a += 5;
        }
        int b = 0;
        for (int i = 0; i < count; i++) {
            b--;
        }
        long tooks = System.nanoTime() - start;
        System.out.println("serial :" + tooks + " ms; b= " + b);
    }
}
